package com.raven.play.stream.test.javadsl

import akka.stream.alpakka.slick.javadsl.SlickSession
import slick.basic.DatabaseConfig
import slick.dbio.{DBIOAction, NoStream}
import slick.jdbc.H2Profile.api._
import slick.jdbc.{JdbcProfile, SQLActionBuilder, SetParameter}

import scala.concurrent.Future

object ScalaSlickHelper {

//  def runSql(updateSql: String, session: SlickSession): Future[Nothing] = {
//    session.db.run(sqlu"$updateSql")
//  }

  def createSqlAction(updateSql: String): DBIOAction[Int, NoStream, Nothing] = {
    SQLActionBuilder(updateSql, SetParameter.SetUnit).asUpdate
  }

  def createSQLAction(sql: String): SQLActionBuilder = {
    return SQLActionBuilder.apply(Seq.apply(sql), SetParameter.SetUnit)
  }

  def createSession(path: String): SlickSession = {
    val databaseConfig = DatabaseConfig.forConfig[JdbcProfile](path)
    SlickSession.forConfig(databaseConfig)
  }

}
